<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="98px">
      <el-form-item label="设备型号" prop="protocolId">
        <el-input
          v-model="queryParams.protocolId"
          placeholder="请输入设备型号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备唯一编码" prop="uuid">
        <el-input
          v-model="queryParams.uuid"
          placeholder="请输入设备唯一编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报警等级" prop="alarmGrade">
        <el-input
          v-model="queryParams.alarmGrade"
          placeholder="请输入报警等级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="dfList" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="设备型号" align="center" prop="protocolId" />
      <el-table-column label="设备唯一编码" align="center" prop="uuid" />
      <el-table-column label="传感器信息1" align="center" prop="sensor1" />
      <el-table-column label="传感器信息2" align="center" prop="sensor2" />
      <el-table-column label="传感器信息3" align="center" prop="sensor3" />
      <el-table-column label="传感器信息4" align="center" prop="sensor4" />
      <el-table-column label="gps" align="center" prop="gps" />
      <el-table-column label="高度数据" align="center" prop="altitude" />
      <el-table-column label="气压数据" align="center" prop="pressure" />
      <el-table-column label="温度数据" align="center" prop="temperature" />
      <el-table-column label="路径1" align="center" prop="route1" />
      <el-table-column label="路径2" align="center" prop="route2" />
      <el-table-column label="路径3" align="center" prop="route3" />
      <el-table-column label="路径4" align="center" prop="route4" />
      <el-table-column label="气泵报警等级" align="center" prop="pump" />
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['gas:df:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['gas:df:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改东方报警数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="设备型号" prop="protocolId">
          <el-input v-model="form.protocolId" placeholder="请输入设备型号" />
        </el-form-item>
        <el-form-item label="设备唯一编码" prop="uuid">
          <el-input v-model="form.uuid" placeholder="请输入设备唯一编码" />
        </el-form-item>
        <el-form-item label="传感器信息1" prop="sensor1">
          <el-input v-model="form.sensor1" placeholder="请输入传感器信息1" />
        </el-form-item>
        <el-form-item label="传感器信息2" prop="sensor2">
          <el-input v-model="form.sensor2" placeholder="请输入传感器信息2" />
        </el-form-item>
        <el-form-item label="传感器信息3" prop="sensor3">
          <el-input v-model="form.sensor3" placeholder="请输入传感器信息3" />
        </el-form-item>
        <el-form-item label="传感器信息4" prop="sensor4">
          <el-input v-model="form.sensor4" placeholder="请输入传感器信息4" />
        </el-form-item>
        <el-form-item label="gps" prop="gps">
          <el-input v-model="form.gps" placeholder="请输入gps" />
        </el-form-item>
        <el-form-item label="高度数据" prop="altitude">
          <el-input v-model="form.altitude" placeholder="请输入高度数据" />
        </el-form-item>
        <el-form-item label="气压数据" prop="pressure">
          <el-input v-model="form.pressure" placeholder="请输入气压数据" />
        </el-form-item>
        <el-form-item label="温度数据" prop="temperature">
          <el-input v-model="form.temperature" placeholder="请输入温度数据" />
        </el-form-item>
        <el-form-item label="路径1" prop="route1">
          <el-input v-model="form.route1" placeholder="请输入报警路径1" />
        </el-form-item>
        <el-form-item label="路径2" prop="route2">
          <el-input v-model="form.route2" placeholder="请输入报警等级2" />
        </el-form-item>
        <el-form-item label="路径3" prop="route3">
          <el-input v-model="form.route3" placeholder="请输入报警路径3" />
        </el-form-item>
        <el-form-item label="路径4" prop="route4">
          <el-input v-model="form.route4" placeholder="请输入报警等级4" />
        </el-form-item>
        <el-form-item label="气泵报警等级" prop="pump">
          <el-input v-model="form.pump" placeholder="请输入气泵报警等级" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDf, getDf, delDf, addDf, updateDf } from "@/api/gas/df";

export default {
  name: "Df",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 东方报警数据表格数据
      dfList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        protocolId: null,
        uuid: null,
        sensor1: null,
        sensor2: null,
        sensor3: null,
        sensor4: null,
        gps: null,
        altitude: null,
        pressure: null,
        temperature: null,
        route1: null,
        route2: null,
        route3: null,
        route4: null,
        pump: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询东方报警数据列表 */
    getList() {
      this.loading = true;
      listDf(this.queryParams).then(response => {
        this.dfList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        protocolId: null,
        uuid: null,
        sensor1: null,
        sensor2: null,
        sensor3: null,
        sensor4: null,
        gps: null,
        altitude: null,
        pressure: null,
        temperature: null,
        route1: null,
        route2: null,
        route3: null,
        route4: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        pump: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加东方报警数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDf(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改东方报警数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDf(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDf(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除东方报警数据编号为"' + ids + '"的数据项？').then(function() {
        return delDf(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('gas/df/export', {
        ...this.queryParams
      }, `df_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
